import { createRouter, createWebHistory } from 'vue-router'
import HomeView from '../views/HomeView.vue'
import store from '@/store'
const routes = [
  {
    path: '/',
    name: 'home',
    component: HomeView
  },
  {
    path: '/itemMusic',
    name: 'ItemMusic',

    component: () => import(/* webpackChunkName: "ItemMusic" */ '../views/ItemMusic.vue')
  },
  {
    path: '/searchview',
    name: 'SearchView',
    component: () => import(/* webpackChunkName: "SearchView" */ '../views/SearchView.vue')
  },
  {
    path: '/medioview',
    name: 'MedioView',
    component: () => import(/* webpackChunkName: "ItemMusic" */ '../views/MedioView.vue')
  },
  {
    path: '/yuncunview',
    name: 'YunCunView',
    component: () => import(/* webpackChunkName: "ItemMusic" */ '../views/YunCunView.vue')
  },
  {
    path: '/findview',
    name: 'FindView',
    component: () => import(/* webpackChunkName: "ItemMusic" */ '../views/FindView.vue')
  },
  {
    path: '/mineview',
    name: 'MineView',
    // 路由守卫
    beforeEnter: (to, from, next) => {
      if (store.state.isLogin || localStorage.getItem('token')) {
        next()
      } else {
        next('/login')
      }
    },
    component: () => import(/* webpackChunkName: "ItemMusic" */ '../views/MineView.vue')
  },
  {
    path: '/login',
    name: 'Login',

    component: () => import(/* webpackChunkName: "ItemMusic" */ '../views/Login.vue')
  }
]

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})
// 全局路由守卫
router.beforeEach((to,from)=>{
  if(to.path ==='/login'){
    store.state.isFooterMusic = false
  }else{
    store.state.isFooterMusic = true
  }
})

export default router
